﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.IO;
using System.Windows.Documents;
using System.Windows.Forms;

namespace DesktopNotes
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : System.Windows.Application
    {
        public void CloseAll_Click(object sender, EventArgs e)
        {
            this.Shutdown();
        }


        public void ShowNotes_Click(object sender, EventArgs e)
        {
            foreach (NotesWindow WindowContext in WindowContexts)
            {
                WindowContext.Topmost = true;
            }
        }

        public List<NotesWindow> WindowContexts = new List<NotesWindow>();


        public App()
        {
            NotifyIcon NewIcon = new NotifyIcon();
            NewIcon.Icon = System.Drawing.SystemIcons.Application;
            MenuItem[] test = new MenuItem[3];
            test[0] = new MenuItem("New Note");
            test[1] = new MenuItem("Show Notes", new EventHandler(ShowNotes_Click));
            test[2] = new MenuItem("Close All Notes", new EventHandler(CloseAll_Click));
            NewIcon.ContextMenu = new ContextMenu(test);

            NewIcon.Visible = true;
            NewIcon.ShowBalloonTip(10, "DesktopNotes", "Notes are pinned to Desktop", ToolTipIcon.Info);

            DirectoryInfo StartupDirectory = new DirectoryInfo(System.Environment.CurrentDirectory);
            foreach (FileInfo File in StartupDirectory.GetFiles("*.note"))
            {
                StreamReader NewReader = new StreamReader(File.FullName);

                NotesWindow newWindow = new NotesWindow();
                newWindow.Title.Content = NewReader.ReadLine();
                newWindow.FileName = File.FullName;
                TextRange textRange = new TextRange(newWindow.RTBText.Document.ContentStart, newWindow.RTBText.Document.ContentEnd);
                textRange.Text = NewReader.ReadToEnd();
                NewReader.Close();
                newWindow.Show();
                WindowContexts.Add(newWindow);
            }
        }
    }
}
